

#include "wxsMarker.h"
#include <wxwidgets/wxsitemresdata.h>


namespace
{


    #include "images/marker16.xpm"
    #include "images/marker32.xpm"

    wxsRegisterItem<wxsMarker> Reg(
        _T("mpMarker"),                
        wxsTWidget,                    
        _T("wxWindows"),               
        _T("Ron Collins"),             
        _T("rcoll@theriver.com"),      
        _T(""),                        
        _T("MathPlot"),                
        60,                            
        _T("Marker"),                  
        wxsCPP,                        
        1, 0,                          
        wxBitmap(marker32_xpm),        
        wxBitmap(marker16_xpm),        
        false);                        


    WXS_ST_BEGIN(wxsMarkerStyles,_T(""))
        WXS_ST_CATEGORY("mpMarker")
        WXS_ST(wxST_NO_AUTORESIZE)
        WXS_ST(wxALIGN_LEFT)
        WXS_ST(wxALIGN_RIGHT)
        WXS_ST(wxALIGN_CENTRE)
        WXS_ST_DEFAULTS()
    WXS_ST_END()

    WXS_EV_BEGIN(wxsMarkerEvents)
    WXS_EV_END()

}


wxsMarker::wxsMarker(wxsItemResData* Data):
    wxsWidget(
        Data,
        &Reg.Info,
        wxsMarkerEvents,
        wxsMarkerStyles) {
    mLabel = _("*");
    mXpos  = _("0.0");
    mYpos  = _("0.0");
}



void wxsMarker::OnBuildCreatingCode() {
wxString    vname;
wxString    pname;
wxString    cname;
wxString    fname;
wxString    xname;
wxString    yname;
wxString    dtext;
wxString    s;


    if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsMarker::OnBuildCreatingCode"),GetLanguage());


    vname = GetVarName();
    pname = GetParent()->GetVarName();
    cname = vname + _("_PEN");
    fname = vname + _("_FONT");


    AddHeader(_T("<mathplot.h>"),GetInfo().ClassName,hfInPCH);


    Codef(_T("%s = new mpMarker(%t, %s, %s);\n"), vname.wx_str(), mLabel.wx_str(), mXpos.wx_str(), mYpos.wx_str());


    dtext = mPenColour.BuildCode(GetCoderContext());
    if (dtext.Len() > 0) {
        Codef(_T("wxPen   %s(%s);\n"), cname.wx_str(), dtext.wx_str());
        Codef(_T("%s->SetPen(%s);\n"), vname.wx_str(), cname.wx_str());
    };


    dtext = mPenFont.BuildFontCode(fname, GetCoderContext());
    if (dtext.Len() > 0) {
        Codef(_T("%s"), dtext.wx_str());
        Codef(_T("%s->SetFont(%s);\n"), vname.wx_str(), fname.wx_str());
    };


    if ((GetPropertiesFlags() & flHidden) && GetBaseProps()->m_Hidden)
        ;
    else
        Codef(_T("%s->AddLayer(%s);\n"), pname.wx_str(), vname.wx_str());


}


wxObject* wxsMarker::OnBuildPreview(wxWindow* Parent, long Flags) {
wxStaticText    *Preview;
mpMarker        *mk;
mpWindow        *mp;
wxPen           pen;
wxColour        cc;
wxFont          ff;
bool            hide;
double          xp, yp;


    if (! Parent->IsKindOf(CLASSINFO(mpWindow))) return NULL;
    mp = (mpWindow *) Parent;


    hide = ((Flags & pfExact) && (GetPropertiesFlags() & flHidden) && GetBaseProps()->m_Hidden);


    Preview = new wxStaticText(Parent, GetId(), mLabel, Pos(Parent), Size(Parent), (wxSUNKEN_BORDER|Style()));
    Preview->SetForegroundColour(wxColour(255,255,255));
    Preview->SetBackgroundColour(wxColour(0,128,0));
    SetupWindow(Preview,Flags);
    if (Flags & pfExact) Preview->Hide();


    cc = mPenColour.GetColour();
    if (cc.IsOk()) pen.SetColour(cc);


    ff = mPenFont.BuildFont();


    if (cc.IsOk()) Preview->SetBackgroundColour(cc);
    Preview->SetFont(ff);


    if (! mXpos.ToDouble(&xp)) {
        xp = 0.0;
        mXpos = _("0.0");
    };
    if (! mYpos.ToDouble(&yp)) {
        yp = 0.0;
        mYpos = _("0.0");
    };


    mk = new mpMarker(mLabel, xp, yp);
    mk->SetPen(pen);
    mk->SetFont(ff);


    if (! hide) mp->AddLayer(mk);


    return Preview;
}



void wxsMarker::OnBuildDeclarationsCode() {

    if (GetLanguage() == wxsCPP) {
        AddDeclaration(_T("mpMarker   *") + GetVarName() + _T(";"));
    }
    else {
        wxsCodeMarks::Unknown(_T("wxsMarker::OnBuildDeclarationsCode"),GetLanguage());
    };
}





void wxsMarker::OnEnumWidgetProperties(cb_unused long Flags) {

    WXS_SHORT_STRING(wxsMarker, mLabel,      _("Marker Text"),     _("mLabelText"),  _("*"), true);
    WXS_SHORT_STRING(wxsMarker, mXpos,       _("X Position"),      _("mXpos"),       _("0.0"), true);
    WXS_SHORT_STRING(wxsMarker, mYpos,       _("Y Position"),      _("mYpos"),       _("0.0"), true);
    WXS_COLOUR(      wxsMarker, mPenColour,  _("Pen Colour"),      _("mPenColour"));
    WXS_FONT(        wxsMarker, mPenFont,    _("Pen Font"),        _("mPenFont"));
}
